package com.yang.SpringTest.annotation.aopLearn;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * <p>AspectDemoLog类</p>
 *
 * @author By: chengxuyuanshitang
 * Package com.yang.SpringTest.annotation.aopLearn
 * Ceate Time 2024-04-13 16:31
 */
@Aspect
@Component
public class AspectDemoLog {
    @Pointcut("execution(* com.yang.SpringTest.annotation.aopLearn.controller.*.*(..))")
    private void pointCut(){}

    @Before("pointCut()")
    public void beforeLog(){
        System.out.println(" ====== @Before Executing...");
    }

    @After("pointCut()")
    public void afterLog(){
        System.out.println(" ====== @After Executing...");
    }

    @AfterReturning("pointCut()")
    public void afterReturningLog(){
        System.out.println(" ====== @AfterReturning Executing...");
    }

    @AfterThrowing("pointCut()")
    public void afterThrowingLog(){
        System.out.println(" ====== @AfterThrowing Executing...");
    }

    @Around("pointCut()")
    public Object aroundLog(ProceedingJoinPoint pjp){

        Object resultValue = null;

        try{
            System.out.println(" ====== @Around  Executing Starting... ");
            Object[] args = pjp.getArgs();
            resultValue = pjp.proceed(args);
            System.out.println(" ====== @Around  Executing ending... ");
        }catch (Throwable t){
            System.out.println(" ====== @Around  Executing  Exception ... ");
        }finally {
            System.out.println(" ====== @Around  Executing  Finally... ");
        }
        return resultValue;
    }
}

